package com.eshipenet.shipnet.edgeboxrpc.grpc;

import com.eshipenet.shipnet.edgebox.EdgeBoxState;
import com.eshipenet.shipnet.edgebox.IsCmdChannelOn;
import com.eshipenet.shipnet.edgebox.IsDataChannelOn;
import com.eshipenet.shipnet.edgebox.IsOnLine;
import org.apache.ignite.cache.query.QueryCursor;
import org.jetbrains.annotations.NotNull;

import javax.cache.Cache;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class QueryCursorMock implements QueryCursor {

    @Override
    public List getAll() {

        List<Cache.Entry<String,EdgeBoxState>> list = new ArrayList<>();

        Cache.Entry<String,EdgeBoxState> c = new Cache.Entry<String, EdgeBoxState>() {
            @Override
            public String getKey() {
                return "1";
            }

            @Override
            public EdgeBoxState getValue() {
                Timestamp createdAt = new Timestamp(System.currentTimeMillis());

                EdgeBoxState state = new EdgeBoxState();
                state.setId("1");
                state.setIsOnLine(IsOnLine.ONLINE);
                state.setIsCmdChannelOn(IsCmdChannelOn.CMDCHANNELON);
                state.setIsDataChannelOn(IsDataChannelOn.DATACHANNELON);
                state.setCreatedAt(createdAt);
                state.setUpdatedAt(createdAt);
                state.setOnlineAt(createdAt);
                state.setOfflineAt(createdAt);

                return  state;
            }

            @Override
            public <T> T unwrap(Class<T> clazz) {
                return null;
            }
        };


        list.add(c);

        return  list;
    }

    @Override
    public void close() {

    }

    @NotNull
    @Override
    public Iterator iterator() {

        Iterator<Cache.Entry<String, EdgeBoxState>> iterator = getAll().iterator();
        return  iterator;

    }
}
